//
//  Tags.m
//  MKV Metadata Editor
//
//  Created by Marcus Johnson on 10/13/12.
//  Copyright (c) 2012 BumbleBritches57. All rights reserved.
//
#import "TagsParcer.h"
#import "GDataXMLNode.h"
#import "TITLE.h"

@implementation TagsParser

+ (NSString *)dataFilePath:(BOOL)forSave {
    return [[NSBundle mainBundle] pathForResource:@"Party" ofType:@"xml"];
}

+ (Party *)loadParty {
	
    NSString *filePath = [self dataFilePath:FALSE];
    NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:filePath];
    NSError *error;
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData
														   options:0 error:&error];
    if (doc == nil) { return nil; }
	
    NSLog(@"%@", doc.rootElement);
	
    return nil;
	
}


+ (void)saveTags:(Tags *)Tags {
	
    GDataXMLElement * TagsElement = [GDataXMLNode elementWithName:@"Tags"];
	
    for(Tags *Tags in Tags.TITLE) {
		
        GDataXMLElement * TagsElement =
		[GDataXMLNode elementWithName:@"Tags"];
        GDataXMLElement * nameElement =
		[GDataXMLNode elementWithName:@"TITLE" stringValue:tags.name];
        GDataXMLElement * levelElement =
		[GDataXMLNode elementWithName:@"" stringValue:
		 [NSString stringWithFormat:@"%d", player.level]];
        NSString *classString;
        if (player.rpgClass == RPGClassFighter) {
            classString = @"Fighter";
        } else if (player.rpgClass == RPGClassRogue) {
            classString = @"Rogue";
        } else if (player.rpgClass == RPGClassWizard) {
            classString = @"Wizard";
        }
        GDataXMLElement * classElement =
		[GDataXMLNode elementWithName:@"Class" stringValue:classString];
		
        [playerElement addChild:nameElement];
        [playerElement addChild:levelElement];
        [playerElement addChild:classElement];
        [partyElement addChild:playerElement];
    }
	
    GDataXMLDocument *document = [[[GDataXMLDocument alloc]
								   initWithRootElement:partyElement] autorelease];
    NSData *xmlData = document.XMLData;
	
    NSString *filePath = [self dataFilePath:TRUE];
    NSLog(@"Saving xml data to %@...", filePath);
    [xmlData writeToFile:filePath atomically:YES];
	
}

@end